package com.zxm.sunshineaiary.view.flinggallery.view;

import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.view.animation.Transformation;

import com.zxm.sunshineaiary.view.flinggallery.util.Operation;


public class FlingGalleryAnimation extends Animation {

	private Operation mOperation;
	private FingGallery mFingGallery;
	private int stateY;
	private int topY;

	public FlingGalleryAnimation(FingGallery mFingGallery) {
		this.mFingGallery = mFingGallery;
		this.mOperation = Operation.getOperationInstatnce(mFingGallery);
	}

	/**
	 * stateY = mOperation.getStateY(); 
	 * int targetY = mOperation.getDistanceY(stateY); 
	 * TopY = stateY - targetY;
	 * 
	 * @param stateY
	 * @param topY
	 */
	public void setCoordinates(int stateY, int topY) {
		this.stateY=stateY;
		this.topY=topY;
	}

	@Override
	public void initialize(int width, int height, int parentWidth,
			int parentHeight) {
		super.initialize(width, height, parentWidth, parentHeight);
		setDuration(500);
		Interpolator mDecelerateInterpolater = AnimationUtils.loadInterpolator(
				mFingGallery.getContext(),
				android.R.anim.decelerate_interpolator);
		setInterpolator(mDecelerateInterpolater);

		
	}

	@Override
	protected void applyTransformation(float interpolatedTime, Transformation t) {
		int targetY = stateY - (int) (topY * interpolatedTime);
		mOperation.onLayout(0, targetY);
		return;
	}
}
